<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="JAVAWEB," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="JDBC的步骤1&amp;gt; 导包 ==&amp;gt; 导入厂商提供的数据库驱动. ==&amp;gt; mysql-connector-java-5.0.8-bin.jar 2&amp;gt; 注册驱动  3&amp;gt; 连接数据库 4&amp;gt; 操作数据库(执行sql) 5&amp;gt; 关闭资源 JDBC中的类1234DriverManager 用于注册驱动,获得连接	Connection    代表连接 , 获得Stateme">
<meta name="keywords" content="JAVAWEB">
<meta property="og:type" content="article">
<meta property="og:title" content="JDBC总结">
<meta property="og:url" content="http://yoursite.com/2017/01/15/JDBC总结/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="JDBC的步骤1&amp;gt; 导包 ==&amp;gt; 导入厂商提供的数据库驱动. ==&amp;gt; mysql-connector-java-5.0.8-bin.jar 2&amp;gt; 注册驱动  3&amp;gt; 连接数据库 4&amp;gt; 操作数据库(执行sql) 5&amp;gt; 关闭资源 JDBC中的类1234DriverManager 用于注册驱动,获得连接	Connection    代表连接 , 获得Stateme">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-03-14T03:40:56.114Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JDBC总结">
<meta name="twitter:description" content="JDBC的步骤1&amp;gt; 导包 ==&amp;gt; 导入厂商提供的数据库驱动. ==&amp;gt; mysql-connector-java-5.0.8-bin.jar 2&amp;gt; 注册驱动  3&amp;gt; 连接数据库 4&amp;gt; 操作数据库(执行sql) 5&amp;gt; 关闭资源 JDBC中的类1234DriverManager 用于注册驱动,获得连接	Connection    代表连接 , 获得Stateme">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/01/15/JDBC总结/"/>





  <title> JDBC总结 | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/01/15/JDBC总结/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                JDBC总结
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-01-15T10:20:58+08:00">
                2017-01-15
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/JAVAWEB/" itemprop="url" rel="index">
                    <span itemprop="name">JAVAWEB</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="JDBC&#x7684;&#x6B65;&#x9AA4;"><a href="#JDBC&#x7684;&#x6B65;&#x9AA4;" class="headerlink" title="JDBC&#x7684;&#x6B65;&#x9AA4;"></a>JDBC&#x7684;&#x6B65;&#x9AA4;</h3><pre><code>1&gt; &#x5BFC;&#x5305; ==&gt; &#x5BFC;&#x5165;&#x5382;&#x5546;&#x63D0;&#x4F9B;&#x7684;&#x6570;&#x636E;&#x5E93;&#x9A71;&#x52A8;. ==&gt; mysql-connector-java-5.0.8-bin.jar
2&gt; &#x6CE8;&#x518C;&#x9A71;&#x52A8; 
3&gt; &#x8FDE;&#x63A5;&#x6570;&#x636E;&#x5E93;
4&gt; &#x64CD;&#x4F5C;&#x6570;&#x636E;&#x5E93;(&#x6267;&#x884C;sql)
5&gt; &#x5173;&#x95ED;&#x8D44;&#x6E90;
</code></pre><h3 id="JDBC&#x4E2D;&#x7684;&#x7C7B;"><a href="#JDBC&#x4E2D;&#x7684;&#x7C7B;" class="headerlink" title="JDBC&#x4E2D;&#x7684;&#x7C7B;"></a>JDBC&#x4E2D;&#x7684;&#x7C7B;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">DriverManager &#x7528;&#x4E8E;&#x6CE8;&#x518C;&#x9A71;&#x52A8;,&#x83B7;&#x5F97;&#x8FDE;&#x63A5;</span><br><span class="line">	Connection    &#x4EE3;&#x8868;&#x8FDE;&#x63A5; , &#x83B7;&#x5F97;Statement&#x5BF9;&#x8C61;</span><br><span class="line">Statement     &#x8FD0;&#x9001;sql&#x8BED;&#x53E5;</span><br><span class="line">ResultSet	  &#x5C06;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x8FD0;&#x56DE;java&#x7AEF;</span><br></pre></td></tr></table></figure>
<h3 id="DriverManager-&#x7EC6;&#x8282;&#x95EE;&#x9898;"><a href="#DriverManager-&#x7EC6;&#x8282;&#x95EE;&#x9898;" class="headerlink" title="DriverManager &#x7EC6;&#x8282;&#x95EE;&#x9898;"></a>DriverManager &#x7EC6;&#x8282;&#x95EE;&#x9898;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">1&gt; &#x6CE8;&#x518C;&#x9A71;&#x52A8;&#x7684;&#x95EE;&#x9898;.</span><br><span class="line">		DriverManager.registDriver(new Driver()); ==&gt; &#x8BE5;&#x79CD;&#x6CE8;&#x518C;&#x65B9;&#x5F0F;,&#x5728;&#x5C06;&#x6765;&#x7684;&#x5F00;&#x53D1;&#x4E2D; &#x4E0D;&#x8981;&#x4F7F;&#x7528;.</span><br><span class="line">	&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x65B9;&#x5F0F;:</span><br><span class="line">		Class.forName(&quot;com.mysql.jdbc.Driver&quot;);</span><br><span class="line">2&gt;&#x4E3A;&#x4EC0;&#x4E48;?</span><br><span class="line">		&#x5728;&#x9A71;&#x52A8;&#x7C7B;&#x7684;&#x4EE3;&#x7801;&#x4E2D;,&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6709;&#x4E00;&#x4E2A;&#x9759;&#x6001;&#x4EE3;&#x7801;&#x5757;&#x3002; &#x9759;&#x6001;&#x4EE3;&#x7801;&#x5757;&#x4E2D;&#x5DF2;&#x7ECF;&#x505A;&#x4E86;&#x6CE8;&#x518C;&#x9A71;&#x52A8;&#x7684;&#x4E8B;&#x60C5;&#x3002; &#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EA;&#x9700;&#x8981;&#x52A0;&#x8F7D;</span><br><span class="line">	&#x9A71;&#x52A8;&#x7C7B;&#xFF0C;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x8C03;&#x7528;&#x4E86; registDriver &#x65B9;&#x6CD5;&#x3002;</span><br><span class="line">3&gt;&#x4F7F;&#x7528; Class.forName&#x6709;&#x4EC0;&#x4E48;&#x597D;&#x5904;?</span><br><span class="line">		* &#x5982;&#x679C;&#x8C03;&#x7528;registDriver &#x65B9;&#x6CD5;, &#x90A3;&#x4E48;&#x76F8;&#x5F53;&#x4E8E;&#x521B;&#x5EFA;&#x4E86;&#x4E24;&#x4E2A;Driver&#x5BF9;&#x8C61;,&#x6D6A;&#x8D39;&#x8D44;&#x6E90;.</span><br><span class="line">		* &#x4F7F;&#x7528;forname&#x7684;&#x65B9;&#x5F0F;. &#x56E0;&#x4E3A;&#x9A71;&#x52A8;&#x7C7B;&#x7684;&#x540D;&#x79F0;&#x662F;&#x4EE5;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5F62;&#x5F0F;&#x586B;&#x5199;,&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x628A;&#x8BE5;&#x540D;&#x79F0;&#x653E;&#x5230;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;,&#x6BCF;&#x6B21;&#x4ECE;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x8BFB;&#x53D6;.</span><br><span class="line">	&#x90A3;&#x4E48;&#x5207;&#x6362;&#x9A71;&#x52A8;&#x7C7B;&#x5C31;&#x975E;&#x5E38;&#x65B9;&#x4FBF;. &#x4E5F;&#x5C31;&#x610F;&#x5473;&#x7740;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;&#x65B9;&#x4FBF;.</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="&#x83B7;&#x5F97;Connection&#x7684;&#x7EC6;&#x8282;"><a href="#&#x83B7;&#x5F97;Connection&#x7684;&#x7EC6;&#x8282;" class="headerlink" title="&#x83B7;&#x5F97;Connection&#x7684;&#x7EC6;&#x8282;"></a>&#x83B7;&#x5F97;Connection&#x7684;&#x7EC6;&#x8282;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">DriverManager.getConnection(&quot;url&quot;,&quot;&#x7528;&#x6237;&#x540D;&quot;,&quot;&#x5BC6;&#x7801;&quot;);</span><br><span class="line">	</span><br><span class="line">url &#x586B;&#x5199;&#x683C;&#x5F0F;:</span><br><span class="line">	&#x5916;&#x5C42;&#x534F;&#x8BAE;:&#x5185;&#x90E8;&#x534F;&#x8BAE;://&#x4E3B;&#x673A;&#x540D;&#x79F0;[ip&#x5730;&#x5740;]:&#x7AEF;&#x53E3;&#x53F7;/&#x5E93;&#x540D;?&#x53C2;&#x6570;&#x952E;1=&#x53C2;&#x6570;&#x503C;&amp;&#x53C2;&#x6570;&#x952E;2=&#x53C2;&#x6570;&#x503C;</span><br><span class="line">			</span><br><span class="line">	jdbc:mysql://localhost:3306/day15?useUnicode=true&amp;characterEncoding=utf-8</span><br><span class="line">	</span><br><span class="line">&#x7ED3;&#x5408;&#x4E0A;&#x9762;&#x8BF4;&#x7684;&#x65B9;&#x4FBF;&#x5207;&#x6362;&#x6570;&#x636E;&#x5E93;.</span><br><span class="line">	&#x6211;&#x4EEC;&#x5728;&#x4E66;&#x5199;&#x65F6;,&#x4E5F;&#x53EF;&#x4EE5;&#x628A;&#x4E0A;&#x9762;3&#x4E2A;&#x53C2;&#x6570;,&#x5199;&#x5230;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;.</span><br></pre></td></tr></table></figure>
<h3 id="Connection&#x5BF9;&#x8C61;&#x7684;&#x7EC6;&#x8282;&#x95EE;&#x9898;"><a href="#Connection&#x5BF9;&#x8C61;&#x7684;&#x7EC6;&#x8282;&#x95EE;&#x9898;" class="headerlink" title="Connection&#x5BF9;&#x8C61;&#x7684;&#x7EC6;&#x8282;&#x95EE;&#x9898;"></a>Connection&#x5BF9;&#x8C61;&#x7684;&#x7EC6;&#x8282;&#x95EE;&#x9898;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x529F;&#x80FD;:1.&#x4EE3;&#x8868;&#x6570;&#x636E;&#x5E93;&#x7684;&#x94FE;&#x63A5;</span><br><span class="line">	 2.&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x8BE5;&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x8FD0;&#x9001;sql&#x8BED;&#x53E5;&#x7684;Statement&#x5BF9;&#x8C61;</span><br><span class="line">&#x65B9;&#x6CD5;:</span><br><span class="line">	****Statement createStatement()   &#x521B;&#x5EFA;statement&#x5BF9;&#x8C61;</span><br><span class="line">	CallableStatement prepareCall(String sql)  &#x8C03;&#x7528;&#x6570;&#x636E;&#x5E93;&#x7684;&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;(&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x6CA1;&#x5B66;)</span><br><span class="line">	****PreparedStatement prepareStatement(String sql)</span><br></pre></td></tr></table></figure>
<h3 id="Statrment-&#x5BF9;&#x8C61;"><a href="#Statrment-&#x5BF9;&#x8C61;" class="headerlink" title="Statrment &#x5BF9;&#x8C61;"></a>Statrment &#x5BF9;&#x8C61;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#x8BE5;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x4E00;&#x4E2A; &#x5411;&#x6570;&#x636E;&#x5E93;&#x8FD0;&#x9001;sql&#x8BED;&#x53E5;&#x7684; &quot;&#x5C0F;&#x8F66;&quot;;</span><br><span class="line">&#x65B9;&#x6CD5;:</span><br><span class="line">	void addBatch(String sql)  &#x5411;&#x8F66;&#x4E0A;&#x6DFB;&#x52A0;&#x8BED;&#x53E5;. (&#x7528;&#x4E8E;&#x6279;&#x91CF;&#x6267;&#x884C;sql&#x8BED;&#x53E5;); insert update delete</span><br><span class="line">	int[] executeBatch()   &#x5C06;&#x8F66;&#x4E0A;&#x7684;&#x8BED;&#x53E5; &#x8FD0;&#x9001;&#x7ED9;&#x6570;&#x636E;&#x5E93;&#x6267;&#x884C;.  &#x8FD4;&#x56DE;&#x503C;&#x5B58;&#x653E;&#x6BCF;&#x4E2A;&#x8BED;&#x53E5;&#x6267;&#x884C;&#x540E;&#x5F71;&#x54CD;&#x7684;&#x884C;&#x6570;. &#x56E0;&#x4E3A;&#x662F;&#x591A;&#x4E2A;&#x8BED;&#x53E5;,&#x6240;&#x4EE5;&#x7528;&#x6570;&#x7EC4;&#x88C5;.</span><br><span class="line">	void clearBatch() &#x6E05;&#x9664;&#x8F66;&#x4E0A;&#x7684;&#x8BED;&#x53E5;.</span><br><span class="line">	----&#x4EE5;&#x4E0A;3&#x4E2A;&#x65B9;&#x6CD5;&#x662F;&#x6279;&#x91CF;&#x6267;&#x884C;sql&#x76F8;&#x5173;&#x7684;(&#x4E0B;&#x5348;&#x6700;&#x540E;&#x4E00;&#x8282;&#x8BFE;&#x6F14;&#x793A;)----------------------</span><br><span class="line">	boolean execute(String sql)  &#x6267;&#x884C;&#x4E00;&#x4E2A;sql&#x8BED;&#x53E5;. &#x5982;&#x679C;&#x8BE5;&#x8BED;&#x53E5;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x96C6; &#x8FD4;&#x56DE;&#x503C;&#x4E3A;true(select). &#x5982;&#x679C;&#x8BE5;&#x8BED;&#x53E5;&#x4E0D;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x96C6; &#x8FD4;&#x56DE;false(insert update delete);</span><br><span class="line">	ResultSet executeQuery(String sql)  &#x6267;&#x884C;&#x4E00;&#x4E2A;&#x6709;&#x7ED3;&#x679C;&#x96C6;&#x7684;&#x67E5;&#x8BE2;. &#x4F1A;&#x5C06;&#x7ED3;&#x679C;&#x96C6;&#x5305;&#x88C5;&#x5230;resultset&#x5BF9;&#x8C61;&#x4E2D;.(select)</span><br><span class="line">	int executeUpdate(String sql)   &#x6267;&#x884C;&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x7ED3;&#x679C;&#x96C6;&#x7684;&#x8BED;&#x53E5;. &#x4F1A;&#x5C06;&#x8BED;&#x53E5;&#x5F71;&#x54CD;&#x7684;&#x884C;&#x6570;&#x8FD4;&#x56DE;.(insert update delete)</span><br><span class="line"></span><br><span class="line">&#x7ED3;&#x8BBA;: </span><br><span class="line">	&#x6267;&#x884C;&#x67E5;&#x8BE2;&#x8BED;&#x53E5;&#x65F6;&#x4F7F;&#x7528;: executeQuery&#x65B9;&#x6CD5;</span><br><span class="line">	&#x6267;&#x884C;&#x589E;&#x5220;&#x6539;&#x7B49;&#x8BED;&#x53E5;&#x65F6;&#x4F7F;&#x7528;: executeUpdate&#x65B9;&#x6CD5;</span><br></pre></td></tr></table></figure>
<h3 id="ResyltSet-&#x5BF9;&#x8C61;"><a href="#ResyltSet-&#x5BF9;&#x8C61;" class="headerlink" title="ResyltSet &#x5BF9;&#x8C61;"></a>ResyltSet &#x5BF9;&#x8C61;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">	&#x529F;&#x80FD;: &#x5F53;&#x6267;&#x884C;&#x7684;&#x8BED;&#x53E5;&#x662F;&#x67E5;&#x8BE2;&#x8BED;&#x53E5;&#x65F6;, resultSet&#x5BF9;&#x8C61;&#x7528;&#x4E8E;&#x5C01;&#x88C5;&#x67E5;&#x8BE2;&#x7ED3;&#x679C;.</span><br><span class="line">	</span><br><span class="line">	&#x65B9;&#x6CD5;:</span><br><span class="line">		boolean next() &#x8BE5;&#x65B9;&#x6CD5;&#x8BA9;&#x7ED3;&#x679C;&#x96C6;&#x4E2D;&#x7684;&#x6307;&#x9488;(&#x6E38;&#x6807;)&#x5F80;&#x4E0B;&#x79FB;&#x52A8;&#x4E00;&#x884C;.&#x5E76;&#x4E14;&#x5224;&#x65AD;&#x6539;&#x884C;&#x662F;&#x5426;&#x6709;&#x6570;&#x636E;&#x3002; &#x6709;&#x8FD4;&#x56DE;true&#xFF0C;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;false</span><br><span class="line">		String getString(int cloumnCount) &#x4ECE;&#x5F53;&#x524D;&#x6307;&#x5411;&#x7684;&#x884C;&#x4E2D;&#x83B7;&#x5F97;String &#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;.  &#x6839;&#x636E;&#x5217;&#x6240;&#x5728;&#x7684;&#x7D22;&#x5F15;&#x4F4D;&#x7F6E;&#x53D6;.</span><br><span class="line">		String getString(String columnName) &#x4ECE;&#x5F53;&#x524D;&#x6307;&#x5411;&#x7684;&#x884C;&#x4E2D;&#x83B7;&#x5F97;String &#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;. &#x6839;&#x636E;&#x5217;&#x540D;&#x53D6;.</span><br><span class="line">			&#x6570;&#x636E;&#x5E93;&#x7C7B;&#x578B;			&#x5BF9;&#x5E94;&#x7684;Get&#x65B9;&#x6CD5;</span><br><span class="line">-------------------------------------------------</span><br><span class="line">			char/varchar         getString</span><br><span class="line">			int					 getInt</span><br><span class="line">			bigint				 getLong</span><br><span class="line">			float/double    	 getFloat/getDouble</span><br><span class="line">			datetime/timestamp   getDate</span><br></pre></td></tr></table></figure>
<h3 id="ResultSet-&#x5176;&#x5B83;&#x4E86;&#x89E3;&#x5185;&#x5BB9;"><a href="#ResultSet-&#x5176;&#x5B83;&#x4E86;&#x89E3;&#x5185;&#x5BB9;" class="headerlink" title="ResultSet &#x5176;&#x5B83;&#x4E86;&#x89E3;&#x5185;&#x5BB9;"></a>ResultSet &#x5176;&#x5B83;&#x4E86;&#x89E3;&#x5185;&#x5BB9;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">	&#x7ED3;&#x679C;&#x96C6;&#x6EDA;&#x52A8;;</span><br><span class="line">	&#x6EDA;&#x52A8;&#x6307;&#x7684;&#x5C31;&#x662F;&#x6307;&#x9488;&#x7684;&#x4F4D;&#x7F6E;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x5411;&#x4E0B;,&#x8FD8;&#x53EF;&#x4EE5;&#x4EFB;&#x610F;&#x63A7;&#x5236;.</span><br><span class="line">		&#x6D89;&#x53CA;&#x7684;&#x65B9;&#x6CD5;&#x5982;&#x4E0B;:</span><br><span class="line">			 boolean absolute(int row)  &#x5C06;&#x6307;&#x9488;&#x79FB;&#x52A8;&#x5230;&#x6307;&#x5B9A;&#x4F4D;&#x7F6E;. &#x53C2;&#x6570;&#x5C31;&#x662F;&#x4F4D;&#x7F6E;. &#x7B2C;&#x4E00;&#x884C;&#x7684;&#x4F4D;&#x7F6E;&#x662F;1. &#x5982;&#x679C;&#x586B;&#x5199;&#x8D1F;&#x6570;&#x8868;&#x793A;&#x5012;&#x6570;.&#x4F8B;&#x5982;-1=&gt;&#x6700;&#x540E;&#x4E00;&#x884C;. &#x5982;&#x679C;&#x79FB;&#x52A8;&#x8D85;&#x51FA;&#x8303;&#x56F4;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE;false.</span><br><span class="line">			 void afterLast()  &#x5C06;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x6B64; ResultSet &#x5BF9;&#x8C61;&#x7684;&#x672B;&#x5C3E;&#xFF0C;&#x6B63;&#x597D;&#x4F4D;&#x4E8E;&#x6700;&#x540E;&#x4E00;&#x884C;&#x4E4B;&#x540E;&#x3002; (&#x8BE5;&#x884C;&#x6CA1;&#x6709;&#x6570;&#x636E;)</span><br><span class="line">			 void beforeFirst()   &#x5C06;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x6B64; ResultSet &#x5BF9;&#x8C61;&#x7684;&#x5F00;&#x5934;&#xFF0C;&#x6B63;&#x597D;&#x4F4D;&#x4E8E;&#x7B2C;&#x4E00;&#x884C;&#x4E4B;&#x524D;&#x3002;(result&#x7684;&#x521D;&#x59CB;&#x4F4D;&#x7F6E;)</span><br><span class="line">			 boolean first()   &#x5C06;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x7B2C;&#x4E00;&#x884C;</span><br><span class="line">			 boolean last()    &#x5C06;&#x5149;&#x6807;&#x79FB;&#x52A8;&#x5230;&#x6700;&#x540E;&#x4E00;&#x884C;</span><br><span class="line">			 boolean next()   &#x5149;&#x6807;&#x5411;&#x4E0B;&#x79FB;&#x52A8;&#x4E00;&#x884C;.</span><br><span class="line">			 boolean previous()  next&#x53CD;&#x65B9;&#x5411;&#x79FB;&#x52A8;.&#x5411;&#x4E0A;&#x79FB;&#x52A8;&#x4E00;&#x884C;.</span><br><span class="line">//--------------------------------------------------------			 </span><br><span class="line">	&#x4F7F;&#x7528;resultSet&#x4FEE;&#x6539;&#x8BB0;&#x5F55;.</span><br><span class="line">		&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;resultSet &#x662F;&#x4E0D;&#x80FD;&#x53CD;&#x5411;&#x4FEE;&#x6539;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x8BB0;&#x5F55;&#x7684;.  &#x9700;&#x8981;&#x5728;&#x521B;&#x5EFA;Statement&#x5BF9;&#x8C61;&#x65F6;, &#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x53C2;&#x6570; &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x4EA7;&#x751F; &#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x6570;&#x636E;&#x7684;resultSet&#x5BF9;&#x8C61;&#x7684;Statement</span><br><span class="line">		Statement createStatement(int resultSetType, int resultSetConcurrency)  </span><br><span class="line">		&#x53C2;&#x6570;1  resultSetType - &#x7ED3;&#x679C;&#x96C6;&#x7C7B;&#x578B;   </span><br><span class="line">					ResultSet.TYPE_FORWARD_ONLY&#x3001; &#x4E0D;&#x652F;&#x6301;&#x7ED3;&#x679C;&#x96C6;&#x6EDA;&#x52A8;,&#x53EA;&#x80FD;&#x5411;&#x524D;.</span><br><span class="line">					ResultSet.TYPE_SCROLL_INSENSITIVE  &#x652F;&#x6301;&#x6EDA;&#x52A8;, &#x8FDF;&#x949D;,&#x4E0D;&#x654F;&#x611F;&#x7684;&#x7ED3;&#x679C;&#x96C6;.</span><br><span class="line">					ResultSet.TYPE_SCROLL_SENSITIVE    &#x652F;&#x6301;&#x6EDA;&#x52A8;, &#x654F;&#x611F;&#x7684;&#x7ED3;&#x679C;&#x96C6;.</span><br><span class="line"> 		&#x53C2;&#x6570;2  resultSetConcurrency  - &#x7ED3;&#x679C;&#x662F;&#x5426;&#x652F;&#x6301;&#x4FEE;&#x6539;&#x7C7B;&#x578B;</span><br><span class="line">					ResultSet.CONCUR_READ_ONLY 	 &#x4E0D;&#x652F;&#x6301;&#x4FEE;&#x6539;</span><br><span class="line">					ResultSet.CONCUR_UPDATABLE   &#x652F;&#x6301;&#x4FEE;&#x6539;</span><br><span class="line"> </span><br><span class="line">	&#x5229;&#x7528;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x53CD;&#x5411;&#x4FEE;&#x6539;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x6570;&#x636E;:</span><br><span class="line">		String sql = &quot;select * from emp&quot;;</span><br><span class="line">		Statement state = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);</span><br><span class="line">		</span><br><span class="line">		ResultSet rs = state.executeQuery(sql);</span><br><span class="line">		</span><br><span class="line">		rs.next();</span><br><span class="line">		</span><br><span class="line">		rs.updateString(&quot;ename&quot;, &quot;haha&quot;);</span><br><span class="line">		</span><br><span class="line">		rs.updateRow();</span><br><span class="line">	</span><br><span class="line">	&#x7ED3;&#x8BBA;: &#x4E0D;&#x8981;&#x4F7F;&#x7528;resultSet &#x505A;&#x4FEE;&#x6539;&#x7684;&#x64CD;&#x4F5C;.  &#x771F;&#x7684;&#x8981;&#x505A;&#x4FEE;&#x6539; &#x6211;&#x4EEC;&#x8981;&#x624B;&#x5199;update&#x8BED;&#x53E5;&#x6765;&#x505A;.</span><br></pre></td></tr></table></figure>
<h3 id="&#x91CA;&#x653E;&#x8D44;&#x6E90;"><a href="#&#x91CA;&#x653E;&#x8D44;&#x6E90;" class="headerlink" title="&#x91CA;&#x653E;&#x8D44;&#x6E90;"></a>&#x91CA;&#x653E;&#x8D44;&#x6E90;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">1&gt; &#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x91CA;&#x653E;. resultSet &lt; Statement &lt; Connection</span><br><span class="line">2&gt; 3&#x4E2A;&#x90FD;&#x9700;&#x8981;&#x91CA;&#x653E;.</span><br><span class="line">3&gt;&#x91CA;&#x653E;&#x65F6;&#x8C03;&#x7528;close&#x65B9;&#x6CD5;&#x5373;&#x53EF;. &#x5982;&#x679C;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5173;&#x95ED; &#x51FA;&#x73B0;&#x4E86;&#x5F02;&#x5E38;. &#x4E5F;&#x8981;&#x4FDD;&#x8BC1;&#x5176;&#x4ED6;&#x7684;&#x5BF9;&#x8C61;&#x5173;&#x95ED;&#x65B9;&#x6CD5;&#x88AB;&#x8C03;&#x7528;.</span><br><span class="line"></span><br><span class="line">resultSet.close();</span><br><span class="line">Statement.close();</span><br><span class="line">Connection.close();</span><br><span class="line">&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x662F;&#x65E0;&#x6CD5;&#x4FDD;&#x8BC1;&#x4E00;&#x5B9A;&#x90FD;&#x80FD;&#x6267;&#x884C;&#x7684;.</span><br><span class="line"></span><br><span class="line">try{</span><br><span class="line">	resultSet.close();</span><br><span class="line">}catch(Exception e){</span><br><span class="line">	</span><br><span class="line">}finally{</span><br><span class="line">	try{</span><br><span class="line">		Statement.close();</span><br><span class="line">	}catch(Exception e){</span><br><span class="line">	}</span><br><span class="line">	finally{</span><br><span class="line">		try{</span><br><span class="line">			Connection.close();</span><br><span class="line">		}catch(Exception e){</span><br><span class="line">			</span><br><span class="line">		}</span><br><span class="line">	}</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="SQL&#x6CE8;&#x5165;&#x95EE;&#x9898;&#x89E3;&#x51B3;&#x529E;&#x6CD5;"><a href="#SQL&#x6CE8;&#x5165;&#x95EE;&#x9898;&#x89E3;&#x51B3;&#x529E;&#x6CD5;" class="headerlink" title="SQL&#x6CE8;&#x5165;&#x95EE;&#x9898;&#x89E3;&#x51B3;&#x529E;&#x6CD5;"></a>SQL&#x6CE8;&#x5165;&#x95EE;&#x9898;&#x89E3;&#x51B3;&#x529E;&#x6CD5;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#x7528;PrepareStatement&#x5BF9;&#x8C61; &#x4E0E; Statement&#x5BF9;&#x8C61;&#x7684;&#x533A;&#x522B;</span><br><span class="line">		</span><br><span class="line">		1.Statement &#x53EF;&#x4EE5;&#x5148;&#x884C;&#x521B;&#x5EFA;, &#x7136;&#x540E;&#x5C06;sql&#x8BED;&#x53E5;&#x5199;&#x5165;.</span><br><span class="line">		  PrepareStatement &#x5728;&#x521B;&#x5EFA;&#x65F6;&#x4E00;&#x5B9A;&#x8981;&#x4F20;&#x5165; sql&#x8BED;&#x53E5;, &#x56E0;&#x4E3A;&#x5B83;&#x8981;&#x5148;&#x8FD0;&#x9001;&#x5230;&#x6570;&#x636E;&#x5E93;&#x6267;&#x884C;&#x9884;&#x7F16;&#x8BD1;</span><br><span class="line">		  </span><br><span class="line">			api:</span><br><span class="line">					PreparedStatement pst = conn.prepareStatement(sql);</span><br><span class="line">		  </span><br><span class="line">		2. PrepareStatement &#x5728;&#x6267;&#x884C;&#x4E4B;&#x524D; &#x5148;&#x8981;&#x8BBE;&#x7F6E; &#x8BED;&#x53E5;&#x4E2D;&#x7684;&#x53C2;&#x6570;. </span><br><span class="line">			</span><br><span class="line">			api: </span><br><span class="line">				pst.setString(1, name);  -- set&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528;&#x8981;&#x770B; &#x53C2;&#x6570;&#x7684;&#x7C7B;&#x578B;.</span><br><span class="line">				</span><br><span class="line">				char/varchar    setString</span><br><span class="line">				int 			setInt</span><br><span class="line">				double 			setDouble</span><br><span class="line">				datatime/timestamp 	setDate</span><br><span class="line">		3. Statement&#x5BF9;&#x8C61;&#x5728;&#x771F;&#x6B63;&#x6267;&#x884C;&#x65F6; &#x4F20;&#x5165;sql&#x8BED;&#x53E5;</span><br><span class="line">		   PrepareStatement &#x5728;&#x6267;&#x884C;&#x4E4B;&#x524D;&#x5DF2;&#x7ECF; &#x8BBE;&#x7F6E;&#x597D;&#x4E86; sql&#x8BED;&#x53E5; &#x4EE5;&#x53CA;&#x5BF9;&#x5E94;&#x53C2;&#x6570;. &#x6267;&#x884C;&#x65B9;&#x6CD5;&#x4E0D;&#x9700;&#x8981;&#x53C2;&#x6570;</span><br><span class="line">			</span><br><span class="line">			api:</span><br><span class="line">				ResultSet rs = pst.executeQuery();</span><br></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JAVAWEB/" rel="tag"># JAVAWEB</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/30/FloatingActionButton/" rel="next" title="FloatingActionButton">
                <i class="fa fa-chevron-left"></i> FloatingActionButton
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/15/数据库常用语句/" rel="prev" title="数据库常用语句">
                数据库常用语句 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#JDBC的步骤"><span class="nav-number">1.</span> <span class="nav-text">JDBC的步骤</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JDBC中的类"><span class="nav-number">2.</span> <span class="nav-text">JDBC中的类</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DriverManager-细节问题"><span class="nav-number">3.</span> <span class="nav-text">DriverManager 细节问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获得Connection的细节"><span class="nav-number">4.</span> <span class="nav-text">获得Connection的细节</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Connection对象的细节问题"><span class="nav-number">5.</span> <span class="nav-text">Connection对象的细节问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Statrment-对象"><span class="nav-number">6.</span> <span class="nav-text">Statrment 对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ResyltSet-对象"><span class="nav-number">7.</span> <span class="nav-text">ResyltSet 对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ResultSet-其它了解内容"><span class="nav-number">8.</span> <span class="nav-text">ResultSet 其它了解内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#释放资源"><span class="nav-number">9.</span> <span class="nav-text">释放资源</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SQL注入问题解决办法"><span class="nav-number">10.</span> <span class="nav-text">SQL注入问题解决办法</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
